#ifndef _TEAM_MANAGER_H_
#define _TEAM_MANAGER_H_

#include "Define.h"
#include <set>
#include <map>
#include <vector>

// 匹配管理,可以初始多个匹配队列.
// 一局结束后多个玩家可以分散到不同匹配队列中

class CTeamManager
{
    SINGLETON_CLASS_DEFINE(CTeamManager);

public:
    enum
    {
        E_MaxQue_Count = 6,
        E_Timer_BuildTeam = 3000,
    };

    void Init(s32 gameid, s32 count, s32 teamMinCount, s32 teamMaxCount, s32 teamMatchMode);
    void Fini();
    s32 GetQueCount();
    s32 GetUserQueIdx(u64 userid);
    void SetUserQueIdx(u64 userid, s32 idx);
    void AddUser(u64 userid);
    void RemoveUser(u64 userid);
    bool IsWaiting(u64 userid);

private:
    struct _teamQue
    {
        std::set<u64> _que;
    };

	static void _OnTimerBuildTeam(void *data, s32 len);
    void _TimerBuildTeam();
    void _BuildTeam_Common();
    void _BuildTeam_FillRoom();
    void _CommonBuild_1(_teamQue &tque);
    void _FillRoomBuild_1(_teamQue &tque);

private:
    s32 m_gameid;
    s32 m_teamMinCount;
    s32 m_teamMaxCount;
    s32 m_teamMatchMode;

    std::vector<_teamQue> m_teamQue;
    s32 m_timerId;

    struct _userTeamInfo
    {
        s32 _queIdx;
        u64 _lastTime;
    };
    std::map<u64, _userTeamInfo> m_userTeamInfo;
};

#endif

